﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

public partial class _XemDanhSachTinRaoVat : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string sTenDangNhap = (string)Session["TenDangNhap"];
        string sMatKhau = (string)Session["MatKhau"];
        LinQ_RaoVatDataContext linQ = new LinQ_RaoVatDataContext();
        var DanhSachTinRaoVat1 = from TinRaoVat in linQ.TIN_RAO_VATs where TinRaoVat.Deleted == false orderby TinRaoVat.ThoiGianDang descending select TinRaoVat;
        GridView2.DataSource = DanhSachTinRaoVat1;
        GridView2.DataBind();
    }

    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TIN_RAO_VAT objTin = (TIN_RAO_VAT)e.Row.DataItem;
            HyperLink hplTenTin1 = (HyperLink)e.Row.FindControl("hplTenTin1");            
            hplTenTin1.Text = objTin.TenTinRaoVat;
            hplTenTin1.NavigateUrl = "~/RaoVat/ChiTietTinRaoVat.aspx?id=" + objTin.MaTinRaoVat;


            HyperLink hplTenNguoiDung1 = (HyperLink)e.Row.FindControl("hplTenNguoiDung1");
            hplTenNguoiDung1.Text = objTin.NGUOI_DUNG.TenNguoiDung;
            hplTenNguoiDung1.NavigateUrl = "~/ThongTinLienHeNguoiDung.aspx?id=" + objTin.NGUOI_DUNG.MaNguoiDung;
        }
    }
    
    protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView2.PageIndex = e.NewPageIndex;
        LinQ_RaoVatDataContext linQ = new LinQ_RaoVatDataContext();
        var DanhSachTinRaoVat1 = from TinRaoVat in linQ.TIN_RAO_VATs where TinRaoVat.Deleted == false orderby TinRaoVat.ThoiGianDang descending select TinRaoVat;
        GridView2.DataSource = DanhSachTinRaoVat1;
        GridView2.DataBind();
    }
    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}
